#include "PWM.h"

namespace yzrilyzr_dsp{
	u_sample PWM::pwm(u_sample x, u_sample width, u_sample rise, u_sample fall, u_sample delay){
		x+=delay;
		x=x-floor(x);
		if(x<rise) return x*2.0/rise-1.0;
		if(x<rise+width) return 1.0;
		if(x<rise+width+fall) return 1.0-(x-rise-width)*2.0/fall;
		return -1.0;
	}
}